As of iOS 10.3 – one of the awaited features provided by Apple.
Why you need to change your app icon after app has been live on the AppStore?
There's a sample code waiting for you by end of this article.
Use cases:
- Your user purchases the full version of your app using in in-app purchase within the app. You might need to change your app icon from “Free” to “Pro”.
- You have some promotions coming in a specific month, you would like to change the app icon when user opens the app in that month. Example: Winter or Summer promotions.
- To show the current city as icon for a City Guide application. Example: If a user is currently in Mumbai, you can change the app icons to Mumbai. May be the Gateway of India in your application icon.
- And many more. Tell me yours in comments.
How to do this?
Add the following keys inside your info.plist. See the CFBundleAlternateIcons for reference.
<key>CFBundleIcons</key> <dict> <key>CFBundleAlternateIcons</key> <dict> <key>city_mumbai</key> <dict> <key>CFBundleIconFiles</key> <array> <string>ic_mumbai</string> </array> <key>UIPrerenderedIcon</key> <false/> </dict> <key>city_newyork</key> <dict> <key>CFBundleIconFiles</key> <array> <string>ic_newyork</string> </array> <key>UIPrerenderedIcon</key> <false/> </dict> <key>city_sydney</key> <dict> <key>CFBundleIconFiles</key> <array> <string>ic_sydney</string> </array> <key>UIPrerenderedIcon</key> <false/> </dict> </dict> <key>CFBundlePrimaryIcon</key> <dict> <key>CFBundleIconFiles</key> <array> <string>ic_london</string> </array> </dict> </dict>
We have added three alternate icons for different cities in [key : icon_name form]:
You should use these keys at the time of setting the app icon.
city_mumbai: ic_mumbai city_newyork: ic_newyork city_sydney: ic_sydney
So once you’re ready with your info.plist file, to change the app icon:
UIApplication.shared.setAlternateIconName("city_mumbai") { (error) in if let error = error { print("Error while changing the app icon: \(error)") } else { print("Icon Set!") } }
This will set the app icon to city_mumbai(i.e. ic_mumbai), if user’s current location is Mumbai.
To reset from alternative to primary icon:
UIApplication.shared.setAlternateIconName(nil)
Limitations:
- User will see an alert every time you try changing the app icon.
- iOS only refers to your app resource folder means can’t use dynamic icons.
- You can’t use the Assets folder to reference the app icons.
- All the icons will be review by Apple’s Review Team before you could change it.
Here is a sample code on Github.